<?php $baseUrl=Zend_Controller_Front::getInstance()->getBaseUrl(); ?>
<input type="hidden" id="uid" value="<?php echo $this->uid; ?>" />
<input type="hidden" id="eid" value="<?php echo $this->eid; ?>" />
<input type="hidden" id="baseUrl" value="<?php echo $baseUrl; ?>"/>

<script type="text/javascript" src="<?php  echo $baseUrl; ?>/js/commonfunctions.js"></script>
<script type="text/javascript" language="javascript">
    var baseUrl=$("#baseUrl").val();
    function postComment()
    {
        //if(StandardString(tinyMCE.get('new_comment').getContent()).toString().length==0)
        if(StandardString($('#new_comment').val()).toString().length==0)
        {
            alert("Chưa nhập nội dung bình luận");
            return;
        }

        //var content=StandardString(tinyMCE.get('new_comment').getContent());
        var content=StandardString($('#new_comment').val()).toString();
        var urlDes = encodeURI(baseUrl + '/community/event/addcomment');//?uid='+$('#uid').val()+'&bid='+$('#bid').val()+'&content='+content);
        $.ajax({
              type:'POST',
              //async: true,
              //cache: false,
              data:{
                  'uid':$('#uid').val(),
                  'eid':$('#eid').val(),
                  'content':content
              },
              timeout: 30000,
              url: urlDes ,
              beforeSend: function(){

              },
              success:function(data)
              {
                //alert(data);
                if(data!="")
                {
                    //tinyMCE.get('new_comment').setContent(data);
                    $('#new_comment').val("");
                    var tbcomment=$('#tbcomment').html();
                    $('#tbcomment').html(tbcomment + data);
                }
                else
                {
                    alert("Không thêm được bình luận!");
                }
              }
        });
    }
</script>
<div class="header">
    <h4>
        <a href="<?php echo $baseUrl .'/community' ?>">Cộng đồng</a>
        <span class="separate">&gt;</span>
        <a href="<?php echo $baseUrl .'/community/event/index' ?>">Sự kiện</a>
        <span class="separate">&gt;</span>
        <a href="#"><?php echo $this->event["title"]; ?></a>
    </h4>
</div>
<div class="clear"></div>
<div>
   <table class="comment" id="tbcomment" width="100%" cellspacing="0" cellpadding="5px">
        <tr>
            <td width="60px">
                <img class="avatar" alt="" src="<?php echo $this->event["user_image"];?>" /><br/><br/>
                <span style="font-weight: bold; display:inline-block;float:left; padding:0 3px;">
                    <?php echo $this->event["user_name"];?>
                </span>
            </td>
            <td>
                <?php echo $this->event["content"]; ?>
              <br/>
               <div style="float:left;">
                   <span><?php echo 'Viết vào lúc '.$this->event["date"]; ?></span>
               </div>
            </td>
        </tr>
        <?php
        if(isset($this->event["comment"]) && count($this->event["comment"])>0)
        {
            foreach($this->event["comment"] as $comment)
            {
        ?>
            <tr id="<?php echo 'tr'.$comment["stt"]; ?>">
                <td width="80px">
                    <img class="avatar" alt="" src="<?php echo $comment["user_image"];?>" /><br/><br/>
                    <span style="font-weight: bold; display:inline-block;float:left; padding:0 3px;">
                        <?php echo $comment["user_name"];?>
                    </span>
                </td>
                <td>
                    <?php echo $comment["content"]; ?>
                   <br/><br/>
                   <?php echo 'Bình luận vào '.$comment["date"]; ?>
                </td>
            </tr>
        <?php
            }
        }
        ?>
    </table>

    <div class="clear"></div>
    <div>
        <div>
            <?php
                if($this->username ==null)
                {
            ?>
                <a class="menu" href="<?php echo $baseUrl .'/default/index/login' ?>"> Đăng nhập</a>
                để cùng chia sẻ.<br />
            <?php
                }
                else
                {
            ?>
                Viết bình luận<br/>
            <?php
                }
            ?>
        </div>
        <br/>
        <textarea rows="8" id="new_comment" name="new_comment" style="width: 99%; border:solid 1px #9baaae;">
        </textarea>
        <br/>
         <?php
                if($this->username !=null)
                {
                    echo '<input onclick="postComment()" type="button" id="post" name="post" value="Bình luận" style="float:right;"/>';
                }
         ?>

    </div>
</div>